home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / PASSDK30.ZIP;1 / DISK1.ZIP / PAS / SUBS / MIXERS / MIXERC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-12  |  8.2 KB  |  298 lines

  1. /*$Author:   DCODY  $*/
  2. /*$Date:   12 Nov 1992 10:00:48  $*/
  3. /*$Header:   X:/sccs/mixers/mixerc.c_v   1.4   12 Nov 1992 10:00:48   DCODY  $*/
  4. /*$Log:   X:/sccs/mixers/mixerc.c_v  $
  5.  * 
  6.  *    Rev 1.4   12 Nov 1992 10:00:48   DCODY
  7.  * fixed a bug with not initializing mvver. Changes were made for
  8.  * Borland 'C' compatibility.
  9.  * 
  10.  *    Rev 1.3   27 Jul 1992 12:02:46   DCODY
  11.  * initialized the 32 bit vectors to 0 so they are placed in the initialized
  12.  * static data segment.
  13.  * 
  14.  *    Rev 1.2   25 Jun 1992 23:49:44   DCODY
  15.  * Simplified the routine by eliminating the static linked and disk
  16.  * resident driver loading.
  17.  * 
  18.  *    Rev 1.1   23 Jun 1992 16:45:12   DCODY
  19.  * PAS2 update
  20.  * 
  21.  *    Rev 1.0   15 Jun 1992 09:41:34   BCRANE
  22.  * Initial revision.
  23. */
  24. /*$Logfile:   X:/sccs/mixers/mixerc.c_v  $*/
  25. /*$Modtimes$*/
  26.  
  27. ;    /*\
  28. ;---|*|----====< MIXERC.C >====----
  29. ;---|*|
  30. ;---|*| Initialize and setup the access to the mixers, volume, filter, etc
  31. ;---|*|
  32. ;---|*| Copyright (c) 1991, Media Vision, Inc. All rights reserved
  33. ;---|*|
  34. ;    \*/
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. // #include "mixbin.h"              // the actual mixer code
  39. #include "state.h"                  // the state structure
  40.  
  41.         int  ThePASDMAChannel = 0;    // DMA channel
  42.         int  ThePASIRQChannel = 0;    // IRQ channel
  43.  
  44.         static int dummyroutine        ();
  45.  
  46.         int (far *MVSetMixerFunction)  () = 0;
  47.         int (far *MVSetVolumeFunction) () = 0;
  48.         int (far *MVSetFilterFunction) () = 0;
  49.         int (far *MVSetCrossChannel)   () = 0;
  50.         int (far *MVGetMixerFunction)  () = 0;
  51.         int (far *MVGetVolumeFunction) () = 0;
  52.         int (far *MVGetFilterFunction) () = 0;
  53.         int (far *MVGetCrossChannel)   () = 0;
  54.         int (far *MVRealSoundSwitch)   () = 0;
  55.         int (far *MVFMSplitSwitch)       () = 0;
  56.  
  57. #define STATICDRIVER    0x0000        // The static driver is loaded.
  58. #define DOSDRIVER        0x0001        // The DOS driver is loaded.
  59. // #define DISKDRIVER    0x0002        // The Disk resident driver is loaded.
  60.  
  61.         // shadow pointer has the active state table pointer
  62.  
  63.         extern struct MVState far *mvhwShadowPointer;
  64.  
  65.         // MVMixerHWState allows the pointer to be changed
  66.  
  67.         struct MVState far *MVMixerHWState(struct MVState far *);
  68.  
  69. ////
  70. ////  /*\
  71. ////  |*|----====< test code >====----
  72. ////  |*|
  73. ////  |*| this is test code to be removed
  74. ////  |*|
  75. ////  \*/
  76. //// int main()
  77. //// {
  78. ////
  79. ////    // In each of the following calls, MVInitMixerCode will search for
  80. ////    // the DOS driver, "MVSOUND.SYS". If found, all succeeding calls to
  81. ////    // the mixers will be routed through MVSOUND.SYS. If the DOS driver
  82. ////    // is not found, then either the DISK based version, or the static
  83. ////    // version will be used. To select the DISK based version, pass a
  84. ////    // path to MVInitMixerCode. Any pointer (other than a NULL) will tell
  85. ////    // the routine to load the driver from the disk. NOTE: If loading from
  86. ////    // the disk fails, then the static driver will be used.
  87. ////
  88. ////    //
  89. ////    // EXAMPLE #1 - The following will attempt to
  90. ////    //                load the driver from the disk.
  91. ////
  92. ////        MVInitMixerCode ( "." );
  93. ////
  94. ////    //
  95. ////    // EXAMPLE #2 - the following will use the
  96. ////    //                static built-in driver.
  97. ////
  98. ////        MVInitMixerCode ( 0 );
  99. //// }
  100. ////
  101.  
  102. ;    /*\
  103. ;---|*|----====< MVInitMixerCode >====----
  104. ;---|*|
  105. ;---|*| Load link to the DOS driver, or load the mixer code
  106. ;---|*|
  107. ;---|*| Entry Conditions:
  108. ;---|*|     char *path is the path to the disk resident driver.
  109. ;---|*|
  110. ;---|*| Return Value:
  111. ;---|*|      0, the mixer code is using the static driver.
  112. ;---|*|      1, the mixer code is using DOS driver.
  113. ;---|*|
  114. ;    \*/
  115.  
  116. int MVInitMixerCode()
  117. {
  118. char *p,*p1;
  119. int n,mx,tablelen;
  120. long far *bfp;            // buffer far pointer
  121. long far *tfp;            // table far pointer
  122.  
  123. long       mvver = 0;    // MVSOUND.SYS version #
  124. static int retry = 0;    // reentry flag. We will only execute once
  125. static int retcode = 0;
  126.  
  127.     // exit if this code has already been executed
  128.  
  129.         if (retry++)
  130.             return(retcode);
  131.  
  132.     // flush some variables
  133.  
  134.         mx = 0;
  135.  
  136.         _asm {
  137.  
  138.             // fill in the functions in case MVSOUND.SYS is not loaded
  139.  
  140.             mov     bx, offset dummyroutine
  141.             mov     word ptr [MVSetMixerFunction+0],bx
  142.             mov     word ptr [MVSetMixerFunction+2],cs
  143.  
  144.             mov     word ptr [MVSetVolumeFunction+0],bx
  145.             mov     word ptr [MVSetVolumeFunction+2],cs
  146.  
  147.             mov     word ptr [MVSetFilterFunction+0],bx
  148.             mov     word ptr [MVSetFilterFunction+2],cs
  149.  
  150.             mov     word ptr [MVSetCrossChannel+0],bx
  151.             mov     word ptr [MVSetCrossChannel+2],cs
  152.  
  153.             mov     word ptr [MVGetMixerFunction+0],bx
  154.             mov     word ptr [MVGetMixerFunction+2],cs
  155.  
  156.             mov     word ptr [MVGetVolumeFunction+0],bx
  157.             mov     word ptr [MVGetVolumeFunction+2],cs
  158.  
  159.             mov     word ptr [MVGetFilterFunction+0],bx
  160.             mov     word ptr [MVGetFilterFunction+2],cs
  161.  
  162.             mov     word ptr [MVGetCrossChannel+0],bx
  163.             mov     word ptr [MVGetCrossChannel+2],cs
  164.  
  165.             mov     word ptr [MVRealSoundSwitch+0],bx
  166.             mov     word ptr [MVRealSoundSwitch+2],cs
  167.  
  168.             mov     word ptr [MVFMSplitSwitch+0],bx
  169.             mov     word ptr [MVFMSplitSwitch+2],cs
  170.  
  171.         // deterine if the DOS driver is loaded
  172.  
  173.             mov     ax,0xbc00                // function 0 is for ID
  174.             mov     bx,0x3f3f
  175.             sub     cx,cx
  176.             sub     dx,dx
  177.             int     2fh                     // go get it...
  178.             xor     bx,cx                    // combine all registers
  179.             xor     bx,dx
  180.             cmp     bx,0x4d56                // to form 'MV'
  181.             jnz     mvininodosdriver
  182.  
  183.             mov     ax,0xbc01                // get the version
  184.             int     2fh
  185.  
  186.             mov     word ptr [mvver+0],bx    // save the version
  187.             mov     word ptr [mvver+2],cx
  188.  
  189.         // the DOS driver is loaded, use it's vectors, data, etc
  190.  
  191.             sub     cx,cx                    // comes back 0 or the entry length
  192.             mov     ax,0xbc03                // get the vector table
  193.             int     0x2f                    // from the DOS driver
  194.  
  195.             mov     word ptr [tfp+0],bx     // save the function pointer offset
  196.             mov     word ptr [tfp+2],dx     // and segment
  197.             mov     [tablelen],cx
  198.  
  199.             mov     ax,0bc04h                // get the DMA & IRQ
  200.             int     0x2f                    // from the DOS driver
  201.  
  202.             mov     byte ptr ThePASDMAChannel,bl    // DMA channel
  203.             mov     byte ptr ThePASIRQChannel,cl    // IRQ channel
  204.  
  205.         } mvininodosdriver:
  206.  
  207.     // we have the pointer to some table. Now, load each function
  208.     // pointer into the individual far pointers.
  209.  
  210.         if (mvver > 0x30313032)         // ASCII version 0102
  211.             retcode = DOSDRIVER;        // indicate the DOS driver is loaded
  212.  
  213.     // set the first 4 (1st rev of MVSOUND just had 4 functions)
  214.  
  215.         (long) MVSetMixerFunction  = (long) *tfp++;
  216.         (long) MVSetVolumeFunction = (long) *tfp++;
  217.         (long) MVSetFilterFunction = (long) *tfp++;
  218.         (long) MVSetCrossChannel   = (long) *tfp++;
  219.  
  220.     // set the next entries (later revs of MVSOUND had 10 functions)
  221.  
  222.         if (tablelen > 4) {
  223.             (long) MVGetMixerFunction  = (long) *tfp++;
  224.             (long) MVGetVolumeFunction = (long) *tfp++;
  225.             (long) MVGetFilterFunction = (long) *tfp++;
  226.             (long) MVGetCrossChannel   = (long) *tfp++;
  227.             (long) MVRealSoundSwitch   = (long) *tfp++;
  228.             (long) MVFMSplitSwitch       = (long) *tfp;
  229.         }
  230.  
  231.     // return the code
  232.  
  233.     return retcode;
  234. }
  235.  
  236.  
  237. ;    /*\
  238. ;---|*|----====< MVMixerHWState >====----
  239. ;---|*|
  240. ;---|*| fetch and/or load a pointer to the state table.
  241. ;---|*|
  242. ;---|*| Entry Conditions:
  243. ;---|*|     MVState far *  --  pointer to another table. If NULL (0),
  244. ;---|*|                        the current pointer is only returned. Only
  245. ;---|*|                        non-zero table pointers will be loaded.
  246. ;---|*| Return Value:
  247. ;---|*|      Returns the pointer to the table currently
  248. ;---|*|      used by the mixer code.
  249. ;---|*|
  250. ;    \*/
  251.  
  252. struct MVState far *MVMixerHWState(tbl)
  253.     struct MVState far *tbl;
  254. {
  255.  
  256.     // if the shadow pointer is not initialized, then do it...
  257.  
  258.         if (!mvhwShadowPointer)
  259.             MVInitStatePtr();
  260.  
  261.     // In the first rev of software the static driver could receive
  262.     // the caller's state table. Now that the static driver is gone,
  263.     // we don't want to mess with...
  264.  
  265.         //    if (tbl)
  266.         //        mvhwShadowPointer = tbl;
  267.  
  268.     // return the active table
  269.  
  270.         return (tbl);
  271. }
  272.  
  273.  
  274. ;    /*\
  275. ;---|*|----====< static dummyroutine >====----
  276. ;---|*|
  277. ;---|*| This routine no-ops out the function calls in case MVSOUND.SYS
  278. ;---|*| is not loaded.
  279. ;---|*|
  280. ;---|*| Entry Conditions:
  281. ;---|*|     none
  282. ;---|*|
  283. ;---|*| Return Value:
  284. ;---|*|      0
  285. ;---|*|
  286. ;    \*/
  287.  
  288. static int dummyroutine ()
  289. {
  290.     return 0;
  291. }
  292.  
  293. ;    /*\
  294. ;---|*| End of MIXERC.C
  295. ;    \*/
  296.  
  297.  
  298.